<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>strstr 函数的忽略大小写版本</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.stripslashes.html">« stripslashes</a></li>
      <li style="float: right;"><a href="function.strlen.html">strlen »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>strstr 函数的忽略大小写版本</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.stristr" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stristr</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stristr</span> &mdash; <span class="dc-title"><span class="function"><a href="function.strstr.html" class="function">strstr()</a></span> 函数的忽略大小写版本</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stristr-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stristr</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$needle</code></span>, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$before_needle</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   返回 <code class="parameter">haystack</code> 字符串从 <code class="parameter">needle</code> 第一次出现的位置开始到结尾的字符串。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stristr-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">haystack</code></dt>

     <dd>

      <p class="para">
       在该字符串中查找。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">needle</code></dt>

     <dd>

      
 <p class="para">
  Prior to PHP 8.0.0, if <code class="parameter">needle</code> is not a string, it is converted
  to an integer and applied as the ordinal value of a character.
  This behavior is deprecated as of PHP 7.3.0, and relying on it is highly
  discouraged. Depending on the intended behavior, the
  <code class="parameter">needle</code> should either be explicitly cast to string,
  or an explicit call to <span class="function"><a href="function.chr.html" class="function">chr()</a></span> should be performed.
 </p>

     </dd>

    
    
     <dt>
<code class="parameter">before_needle</code></dt>

     <dd>

      <p class="para">
      若为 <strong><code>true</code></strong>，<span class="function"><a href="function.strstr.html" class="function">strstr()</a></span> 将返回 <code class="parameter">needle</code> 在 <code class="parameter">haystack</code> 中的位置之前的部分(不包括 needle)。
      </p>
     </dd>

    
   </dl>

  </p>
  <p class="para">
   参数 <code class="parameter">needle</code> 和 <code class="parameter">haystack</code> 将以不区分大小写的方式对待。
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stristr-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回匹配的子字符串。如果 <code class="parameter">needle</code> 未找到，返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stristr-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      
 <tr>
  <td>8.2.0</td>
  <td>
   大小写转换不在依赖于使用 <span class="function"><a href="function.setlocale.html" class="function">setlocale()</a></span> 设置的区域。只会进行 ASCII
   大小写转换。非 ASCII 字节值将通过它们的字节值进行比较。
  </td>
 </tr>


      <tr>
       <td>8.0.0</td>
       <td>
        不再支持 <span class="type">int</span> 传递给 <code class="parameter">needle</code>。
       </td>
      </tr>

      <tr>
       <td>7.3.0</td>
       <td>
        弃用 <span class="type">int</span> 传递给 <code class="parameter">needle</code>。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stristr-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4843">
    <p><strong>示例 #1 <span class="function"><strong>stristr()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$email&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'USER@EXAMPLE.com'</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'e'</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;输出&nbsp;ER@EXAMPLE.com<br />&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$email</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'e'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;输出&nbsp;US<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4844">
    <p><strong>示例 #2 测试字符串的存在与否</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello&nbsp;World!'</span><span style="color: #007700">;<br />&nbsp;&nbsp;if(</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'earth'</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'"earth"&nbsp;not&nbsp;found&nbsp;in&nbsp;string'</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br /></span><span style="color: #FF8000">//&nbsp;输出:&nbsp;"earth"&nbsp;not&nbsp;found&nbsp;in&nbsp;string<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4845">
    <p><strong>示例 #3 使用非字符串 needle</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'APPLE'</span><span style="color: #007700">;<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">stristr</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">97</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;97&nbsp;=&nbsp;小写字母&nbsp;a<br />//&nbsp;输出:&nbsp;APPLE<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stristr-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stristr-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strstr.html" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
    <li class="member"><span class="function"><a href="function.strrchr.html" class="function" rel="rdfs-seeAlso">strrchr()</a> - 查找指定字符在字符串中的最后一次出现</span></li>
    <li class="member"><span class="function"><a href="function.stripos.html" class="function" rel="rdfs-seeAlso">stripos()</a> - 查找字符串首次出现的位置（不区分大小写）</span></li>
    <li class="member"><span class="function"><a href="function.strpbrk.html" class="function" rel="rdfs-seeAlso">strpbrk()</a> - 在字符串中查找一组字符的任何一个字符</span></li>
    <li class="member"><span class="function"><a href="function.preg-match.html" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>